﻿@using viBook.Models
@model IEnumerable<Book>
<script type="text/javascript">
    function Book(id, title, description,coverUrl,uploadedBy,view,uploader) {
    if(coverUrl==null || coverUrl=="")
        coverUrl="/Images/DefaultbookImage.png";
        return {
            Id: ko.observable(id),
            Title: ko.observable(title),
            Description: ko.observable(description),
            CoverUrl : ko.observable(coverUrl),          
            UploadedBy : ko.observable(uploadedBy),
            View : ko.observable(view),
            Uploader : ko.observable(uploader)
        };
    }

    var initialBookCollection = [
        @foreach (Book item in Model)
        {
            <text>
                new Book(@item.Id, '@item.Title', '@item.Description','@item.CoverUrl',@item.UploadedBy,@item.View,'@item.Uploader'),
            </text>
        }
    ];
    var viewmodel = {
        bookCollection: ko.observableArray(initialBookCollection),
        bookTemplate: ko.observable("ListBookTemplate"),
            };

    ko.applyBindings(viewmodel);
</script>